package com.javasea.web.controller;

import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @date 2019-12-24 14:50:00
 */
@RestController
@RequestMapping("/orders")
public class OrderController {

    /**
     * GET: http://localhost:8080/orders/get1/2020-07-30 23:00:01    前端到后端  使用converter下的   StringToLocalDateTimeConverter
     * @param payTime
     */
    @GetMapping("/get1/{payTime}")
    public void get1(@PathVariable Date payTime) {
        System.out.println(payTime);
    }

    /**
     * GET: http://localhost:8080/orders/get2/2020-07-30 23:00:01
     * @param payTime
     */
    @GetMapping("/get2/{payTime}")
    public void get2(@PathVariable LocalDateTime payTime) {
        System.out.println(payTime);
    }

    /**
     * GET: http://localhost:8080/orders/list  后端到前端 使用的是：
     * JacksonDateSerializer
     * JacksonLocalDateTimeSerializer
     * @return
     */
    @GetMapping("/list")
    public Order list() {
        Order order = new Order();
        order.setPayTime(LocalDateTime.now());
        order.setCreateTime(new Date());
        return order;
    }

    /**
     * GET: http://localhost:8080/orders/add?createTime=2020-07-30 23:00:01  前端到后端 使用  StringToDateConverter
     * GET: http://localhost:8080/orders/add?payTime=2020-07-30 23:00:01  前端到后端 使用  StringToDateConverter
     * @param order
     */
    @GetMapping("/add")
    public void add(Order order) {
        System.out.println(order);
    }

    /**
     * POST: http://localhost:8080/orders/update  {"payTime": "2020-07-30 23:00:01"}  使用  JacksonLocalDateTimeDeserializer
     * POST: http://localhost:8080/orders/update  {"createTime": "2020-07-30 23:00:01"}  使用  JacksonDateDeserializer
     * @param order
     */
    @PostMapping("/update")
    public void update(@RequestBody Order order) {
        System.out.println(order);
    }

}
